
<template>
  <el-form :inline="true" :label-position="'right'"  class="demo-form-inline">
    <el-form-item label="任务">
      <el-input disabled v-model="Form.TASK_NAME.value" placeholder="任务"></el-input>
    </el-form-item>
    <el-form-item label="节点">
      <el-input disabled v-model="Form.ORG_NAME.value" placeholder="节点"></el-input>
    </el-form-item>
    <el-form-item label="处理情况">
      <el-select v-model="Form.RESULT.value" placeholder="处理情况" width="90%">
        <el-option label="完成" value="50250001"></el-option>
        <el-option label="未完成" value="50250002"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="填报人">
      <el-input disabled v-model="Form.USER_NAME.value" placeholder="填报人"></el-input>
    </el-form-item>
    <el-form-item label="联系电话">
      <el-input disabled v-model="Form.LINK_TEL.value" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="填报期限">
      <el-input disabled v-model="Form.TASK_REQ_DATE.value" placeholder="填报期限"></el-input>
    </el-form-item>
    <el-form-item label="核实日期">
      <el-input disabled v-model="Form.TASK_OPR_DATE.value" placeholder="核实日期"></el-input>
    </el-form-item>
    <el-form-item label="备注">
      <el-input v-model="Form.TASK_COMMENT.value" placeholder="备注"></el-input>
    </el-form-item>
      <el-form-item label="客户端设备是否准备好">
      <el-select v-model="Form.CUST_DEVICE_FLAG.value" placeholder="客户端设备是否准备好" width="90%">
        <el-option label="是" value="1"></el-option>
        <el-option label="否" value="2"></el-option>
      </el-select>
    </el-form-item>
      <el-form-item label="楼内线是否具备">
      <el-select v-model="Form.CUST_CIRCUIT_FLAG.value" placeholder="楼内线是否具备" width="90%">
        <el-option label="是" value="1"></el-option>
        <el-option label="否" value="2"></el-option>
      </el-select>
    </el-form-item>
     <el-form-item label="客户机房是否准备好">
      <el-select v-model="Form.CUST_LAB_FLAG.value" placeholder="客户机房是否准备好" width="90%">
        <el-option label="是" value="1"></el-option>
        <el-option label="否" value="2"></el-option>
      </el-select>
    </el-form-item>
     <el-form-item label="是否协调好物业">
      <el-select v-model="Form.CUST_SERV_FLAG.value" placeholder="是否协调好物业" width="90%">
       <el-option label="是" value="1"></el-option>
        <el-option label="否" value="2"></el-option>
      </el-select>
    </el-form-item>
     <el-form-item label="甲端发展人">

        <input-dialog  
                  v-model="Form.OTN_SHENG_JIA.value"
                  text="staffName"
                  @getrow="getRowCustManageHandler"
                  @loadata="loadCustManageOptions"
                  :config="custManageConfig"
              />

    </el-form-item>
     <el-form-item label="乙端发展人">

      <input-dialog  
                  v-model="Form.OTN_SHENG_YI.value"
                  text="staffName"
                  @getrow="getRowCustManageHandler"
                  @loadata="loadCustManageOptions"
                  :config="custManageConfig"
              />

    </el-form-item>
     <el-form-item label="本端发展人">
      <input-dialog
                  v-model="Form.USER_NAME.value"
                  text="staffName"
                  @getrow="getRowCustManageHandler"
                  @loadata="loadCustManageOptions"
                  :config="custManageConfig"
              />

    </el-form-item>
    <el-form-item class="btnDir">
      <el-button @click="onSubmit">保 存</el-button>
      <el-button @click="onCancel">取 消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import requestUtil from '@/utils/requestEnc';
import CustOrderService from "@/api/order/CustOrderService";
import OrderService from "@/api/order/OrderService.js";
import { mapState } from "vuex";
import inputDialog from "@/components/public/forms/inputDialog";
export default {
 components: {
		requestUtil,
    CustOrderService,
    OrderService,
    inputDialog
  },
  computed: {
		...mapState("orders", ["orderItemList"]),
		...mapState("user", ["user"]),
	},
  async mounted(){

    
    
    if(this.CTOInfo.length > 0){
      var orderItemIds="";
     
      this.Form.USER_NAME.value = this.user.staffName;
      this.Form.USER_ID.value = this.user.staffId;
      this.Form.TASK_OPR_DATE.value = this.$util.dateFormat(new Date(),"yyyy-MM-dd");
 
      for(var i=0;i<this.CTOInfo.length;i++){
         if(i==0){
           orderItemIds += this.CTOInfo[i].orderItemId;
         }else{
            orderItemIds += ","+this.CTOInfo[i].orderItemId;
         }
      }
      var scopeInfos=[]
      scopeInfos.push({scope:"orderTasks"});
      var custSoNumber = this.CTOInfo[0].custSoNumber;
      var batchNbr =  this.CTOInfo[0].batchNbr;
      var custId = this.CTOInfo[0].custId;
      var taskId = this.ODKInfo.taskId;
     
      
      this.orderItemIds = orderItemIds;

      let usersMsg = {
        acceptUserId: this.user.staffId,
        acceptUserOrg: this.user.orgId,
        systemUserId: this.user.sysUserId,
        dealType: 234,
        orderItemId:this.CTOInfo[0].orderItemId,
        orderAuditId:this.CTOInfo[0].orderAuditId
      };
     
     const result = await CustOrderService.queryOrderItemDealTask(usersMsg);

      const orderDetailOrders = await CustOrderService.qryCustomerOrderDetail({custSoNumber,batchNbr,orderItemIds,custId,scopeInfos});
      

     
      var  orderTasks = result.meta.orderItemDealTasks;
      // var orderTasks = this.ODKInfo;
      
      for(var i=0;i<orderTasks.length;i++){
        //业务接单
        if(orderTasks[i].taskId == 'TACHE20490001'){
          var orderTask = orderTasks[i];
          break;
        }
      }
      
      var orderDetailTasks = orderDetailOrders.orderDetails[0].orderTasks;
      
      for(var i=0;i<orderDetailTasks.length;i++){
        //业务接单
        if(orderDetailTasks[i].taskId == 'TACHE20490001'){
          var orderDetailTask = orderDetailTasks[i];
          break;
        }
      }
      
       this.Form.TASK_NAME.value = "业务接单";
      this.orderTask = orderTask;
      
      // 

      this.Form.TASK_REQ_DATE.value = orderDetailTask.taskReqDate;
      this.Form.LINK_TEL.value = orderDetailTask.linkTel;
      // this.Form.ORG_NAME.value = orderTask.oprOrgId;
      

      var orgName = await CustOrderService.getOrgName({orgId:this.user.orgId});
      
       this.Form.ORG_NAME.value = orgName;
      
    }else{
      this.Form.TASK_NAME.value = "";
    }


  },
  watch:{


  },
  props:{
	 	ODKInfo: {
			type: Object,
			default: () => {
				return {};
			},
		},
		CTOInfo: {
			type: Array,
			default: () => {
				return [];
			},
		},
  },
  data() {
    return {
    custManageConfig: {
        title: "发展人信息",
        tableData: [],
        tableForm: {
          items: [
            {
              field: "CHANNEL_NBR",
              title: "渠道名称",
              itemRender: {
                name: "select",
                options: [{ label: "请选择",value:"" }],
              },
            },
            {
              field: "OPERATORS_NBR",
              title: "经营主体名称",
              itemRender: {
                 name: "select",
                options: [{ label: "请选择",value:"" }],
              },
              
            },
            {
              field: "PROVINCE_CODE",
              title: "省份",
              itemRender: {
                 name: "select",
                options: [{ label: "请选择",value:"" }],
              },
              
            },
             {
              field: "CITY_CODE",
              title: "本地网",
              itemRender: {
                name: "select",
                options: [{ label: "请选择",value:"" }],
              },
              
            },
            {
              field: "SALES_CODE",
              title: "销售员编码",
              itemRender: {
                name: "input",
                attrs: { placeholder: "" },
              },
              
            },
             {
              field: "STAFF_NAME",
              title: "销售员名称",
              itemRender: {
                name: "input",
                attrs: { placeholder: "" },
              },
              
            },
            {
              itemRender: {
                name: "$button",
                props: { content: "查询", type: "submit", status: "primary" },
              },
            },
          ],
          data: {}, //这个data一定要加，否则无法获取查询参数
        },
        tableColumn: [
          { field: "staffCode", title: "销售员编码" },
          { field: "staffName", title: "销售员名称" },
          { field: "staffName", title: "证件类型" },
          { field: "staffName", title: "证件号码" },
          { field: "staffName", title: "联系手机" },
          { field: "staffName", title: "邮箱" },
          { field: "staffName", title: "组织信息（省市县）" },
          { field: "staffName", title: "状态" },
          { field: "staffName", title: "状态时间" },
        ],
      },
    orderItemIds:"",
    orderTask:{},
     Form:{
	"TASK_NAME":{
		  type: 'Ipt',
          name: '任务',
          colId: "TASK_NAME",
          coltype: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_NAME",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-141000049",
          disabled: true,
          show: true,
          span: 6
	},
	"RESULT":{
		 type: 'Ipt',
          name: '处理情况',
          colId: "RESULT",
          coltype: "C",
          tableName: "ORDER_TASK",
          fieldId: "RESULT",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-141000046",
          disabled: true,
          show: true,
          span: 6
	},
	"USER_NAME":{
		type: 'Ipt',
          name: '填报人',
          colId: "USER_NAME",
          coltype: "C",
          tableName: "ORDER_TASK",
          fieldId: "USER_NAME",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100012377",
          disabled: true,
          show: true,
          span: 6
	},
	"ORG_NAME":{
		type: 'Ipt',
          name: '节点',
          colId: "ORG_NAME",
          coltype: "C",
          tableName: "ORGANIZATION",
          fieldId: "ORG_NAME",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
	},
	"LINK_TEL":{
		type: 'Ipt',
          name: '联系电话',
          colId: "LINK_TEL",
          coltype: "C",
          tableName: "ORDER_TASK",
          fieldId: "LINK_TEL",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
	},
	"TASK_REQ_DATE":{
		type: 'Ipt',
          name: '填报期限',
          colId: "TASK_REQ_DATE",
          coltype: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_REQ_DATE",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
	},
	"TASK_OPR_DATE":{
		type: 'Ipt',
          name: '核实日期',
          colId: "TASK_OPR_DATE",
          coltype: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_OPR_DATE",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
	},
	"TASK_COMMENT":{
		type: 'Ipt',
          name: '备注',
          colId: "TASK_COMMENT",
          coltype: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_COMMENT",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
	},
	"USER_ID":{
		type: 'Ipt',
          name: 'USER_ID',
          colId: "USER_ID",
          coltype: "C",
          tableName: "ORDER_TASK",
          fieldId: "USER_ID",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
  },
  "CUST_DEVICE_FLAG":{
    	type: 'Ipt',
          name: '100012775',
          colId: "100012775",
          coltype: "T",
          tableName: "ORDER_TASK_ATTR",
          fieldId: "CUST_DEVICE_FLAG",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "2335-100012775",
          disabled: true,
          show: true,
          span: 6
  },
   "CUST_CIRCUIT_FLAG":{
    	type: 'Ipt',
          name: '100012680',
          colId: "100012680",
          coltype: "T",
          tableName: "ORDER_TASK_ATTR",
          fieldId: "CUST_CIRCUIT_FLAG",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "2335-100012680",
          disabled: true,
          show: true,
          span: 6
  },
   "CUST_LAB_FLAG":{
    	type: 'Ipt',
          name: '100012750',
          colId: "100012750",
          coltype: "T",
          tableName: "ORDER_TASK_ATTR",
          fieldId: "CUST_LAB_FLAG",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "2335-100012750",
          disabled: true,
          show: true,
          span: 6
  },
  "CUST_SERV_FLAG":{
    	type: 'Ipt',
          name: '100012676',
          colId: "100012676",
          coltype: "T",
          tableName: "ORDER_TASK_ATTR",
          fieldId: "CUST_SERV_FLAG",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "2335-100012676",
          disabled: true,
          show: true,
          span: 6
  },
   "OTN_SHENG_JIA":{
    	type: 'Ipt',
          name: '23836-142002231',
          colId: "142002231",
          coltype: "T",
          tableName: "PROD_INST_ATTR",
          fieldId: "OTN_SHENG_JIA",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "23836-142002231",
          disabled: true,
          show: true,
          span: 6
  },
   "OTN_SHENG_YI":{
    	type: 'Ipt',
          name: '142002236',
          colId: "142002236",
          coltype: "T",
          tableName: "PROD_INST_ATTR",
          fieldId: "OTN_SHENG_YI",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "23837-142002236",
          disabled: true,
          show: true,
          span: 6
  }}}
  },
  methods: {
    async loadCustManageOptions(params) {
      const data = {
        orgId: this.user.orgId, //session里取
        postCode: "014_KHJL", //客户经理  014_KHJL    业务经理  016_XMJLYWJL
        pageSize: "20",
        pageIndex: "1",
        ...params,
      };
      let res = await OrderService.qryStaffList(data);
      if (res.code == 200) {
        this.custManageConfig.tableData = res.meta.staffIdList || [];
      }
    },
    getRowCustManageHandler(row) {
     
    },
	 onCancel(){
		
    //  this.$parent.closeDrawer();
   this.$emit('update:show',false)
	},
  async onSubmit() {
	   
	let msJson = {
    statusCds: this.CTOInfo[0].statusCd, //订单状态
    custSoNumber: this.CTOInfo[0].custSoNumber, //流水号  从上个页面带回
    handleOrgId: this.user.staffId,
    custId: this.CTOInfo[0].custId,
    batchNbr: this.CTOInfo[0].batchNbr, //批次号
		accNum: "", //设备号,没有不传
		orderItemIds:this.orderItemIds,
		taskId:this.orderTask.taskId,
		orderAuditId:this.CTOInfo[0].orderAuditId,
    oneOrmany:"one",
    orderTaskId:this.orderTask.orderTaskId,
    userId:this.user.staffId,
    orderItemId:this.orderItemIds,
    processInstId:this.orderTask.processInstId,
    activityId:this.orderTask.activityInstId
      };

		let param = requestUtil.paramEnc(this.Form,msJson);


		

		var result = await CustOrderService.saveOrderTask({...msJson,...param});
    
    this.$emit("windowClose");
		alert(JSON.parse(result.meta).meta);
    }
  }
}
</script>

<style>
.el-form--inline .el-form-item {
  display: inline-flex;
  margin-right: 0.1rem;
  vertical-align: top;
  width: 42%;
}

.el-form-item__label {
  width: 94px;
}
.btnDir {
  margin-left: 36%;
  margin-top: 19px;
}
</style>
